package com.coach.model;

public abstract class Model {
	
	protected String name;
	
	protected IChangeListener changeListener = ModelChangeListener.getInstance();
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public Model() { }
	
	public Model(String modelName) {
		this.name = modelName;
	}
	
	public abstract void accept(IModelVisitor visitor, Object args);
	
	public abstract void add(Model model);
	public abstract void remove(Model model);
	
	protected void fireAddEvent(Object args) {
		changeListener.add(new ChangeEvent(args));
	}
	
	protected void fireRemoveEvent(Object args) {
		changeListener.remove(new ChangeEvent(args));
		
	}
	
	public void addChangeListener(IChangeListener listener) {
		this.changeListener = listener;
	}
	
	public void removeChangeListener(IChangeListener listener) {
		if (this.changeListener.equals(listener))
			this.changeListener = ModelChangeListener.getInstance();
	}
}
